require(["config"], function() {
    require(["jquery", "header", "cookie"], function($) {
        function Login() {
            this.addListener();
        }
        $.extend(Login.prototype, {
            addListener: function() {
                $(".biao2").on("submit", $.proxy(this.loginHandler, this));
            },
            loginHandler: function() {
                var data = $(".biao2").serialize();
                var url = "http://localhost:921/incake/api/login.php";
                $.post(url, data, this.loginSuccessHandler, "json");
                return false;
            },
            loginSuccessHandler: function(data) {
                console.log(data);
                if (data.res_code === 1) {
                    $.cookie.json = true;
                    $.cookie("login-user", data.res_body.phone, {path: "/"});
                    location = "/index.html";
                } else {
                    $(".login-error").removeClass("hidden");
                }
            }
        })
        new Login();
    });
});